//
//  LGHomeCalenderCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/14.
//

#import "LGHomeCalenderCell.h"

@interface LGHomeCalenderCell()
/**   */
@property (nonatomic , strong)UIView *selectView;
/**   */
@property (nonatomic , strong)UILabel *dayLabel;
/**   */
@property (nonatomic , strong)UILabel *weekLabel;
/**   */
@property (nonatomic , strong)UIView *pointView;
/**   */
@property (nonatomic , strong)NSDateFormatter *formatter;
/**   */
@property (nonatomic , strong)NSArray *weekArray;

@end

@implementation LGHomeCalenderCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.weekArray = @[@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六"];
        [self createSubView];
    }
    return self;
}

-(void)setNormalColor:(NSString *)normalColor{
    _normalColor = normalColor;
    self.dayLabel.textColor = [UIColor colorWithString:normalColor];
    self.weekLabel.textColor = [UIColor colorWithString:normalColor];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSDate *date = [self.formatter dateFromString:LGNSString(dataDic[@"date"])];
    NSDateComponents *component = [[NSCalendar currentCalendar] components:NSCalendarUnitDay|NSCalendarUnitWeekday fromDate:date];
    NSInteger weekDay = [component weekday];
    self.dayLabel.text = [NSString stringWithFormat:@"%.2ld",[component day]];
    if([[self.formatter stringFromDate:[NSDate date]] isEqualToString:LGNSString(dataDic[@"date"])]){
        self.weekLabel.text = @"今天";
    }else{
        self.weekLabel.text = self.weekArray[weekDay-1];
    }
    NSString *status = LGNSString(dataDic[@"status"]);
    if([status isEqualToString:@"0"]){
        //没有点
        self.pointView.hidden = YES;
    }else if ([status isEqualToString:@"1"]){
        //有日程
        self.pointView.hidden = NO;
        self.pointView.backgroundColor = [UIColor colorWithString:@"#429BFF"];
    }else{
        //有逾期
        self.pointView.hidden = NO;
        self.pointView.backgroundColor = [UIColor colorWithString:@"#F84D4D"];
    }
}


-(void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    if(isSelect == YES){
        self.selectView.hidden = NO;
        self.dayLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        self.weekLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        
    }else{
        self.selectView.hidden = YES;
        self.dayLabel.textColor = [UIColor colorWithString:self.normalColor];
        self.weekLabel.textColor = [UIColor colorWithString:self.normalColor];
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.selectView];
    [self.contentView addSubview:self.dayLabel];
    [self.contentView addSubview:self.weekLabel];
    [self.contentView addSubview:self.pointView];
    [self.selectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(5));
        make.centerX.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(44)));
    }];
    [self.dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectView).offset(viewPix(3));
        make.centerX.equalTo(self.contentView);
    }];
    [self.weekLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dayLabel.mas_bottom).offset(2);
        make.centerX.equalTo(self.contentView);
    }];
    [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectView.mas_bottom).offset(viewPix(7));
        make.centerX.equalTo(self.contentView);
        make.width.height.equalTo(@(4));
    }];
}

-(NSDateFormatter *)formatter{
    if(!_formatter){
        _formatter = [[NSDateFormatter alloc]init];
        _formatter.dateFormat = @"yyyy-MM-dd";
    }
    return _formatter;
}

-(UIView *)selectView{
    if(!_selectView){
        _selectView = [[UIView alloc]init];
        _selectView.backgroundColor = [UIColor colorWithString:@"#DFEEFF"];
        _selectView.cornerRidus = viewPix(22);
    }
    return _selectView;
}

-(UILabel *)dayLabel{
    if(!_dayLabel){
        _dayLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dayLabel;
}

-(UILabel *)weekLabel{
    if(!_weekLabel){
        _weekLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _weekLabel;
}

-(UIView *)pointView{
    if(!_pointView){
        _pointView = [[UIView alloc]init];
        _pointView.cornerRidus = 2;
    }
    return _pointView;
}


@end
